﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Globalization;

namespace produccion.forms
{
    /// <summary>
    /// Lógica de interacción para UCDetallePedidoCliente.xaml
    /// </summary>
    public partial class UCDetallePedidoCliente : UserControl
    {
        public UCDetallePedidoCliente()
        {
            InitializeComponent();
        }

        private void datInf2_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
        {
            DataGridBoundColumn c = (DataGridBoundColumn)e.Column;
            c.Binding = new Binding(e.PropertyName) { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged };

            c.IsReadOnly = true;

            // Ocultar columnas en el grid
            if (c.Header.ToString().Equals("CODCLI_TMP") || c.Header.ToString().Equals("NROPED_TMP") || c.Header.ToString().Equals("CODREF_TMP") || c.Header.ToString().Equals("CODCOL_TMP") || c.Header.ToString().Equals("CONSEC_TMP") )
            {
                e.Cancel = true;
            }

            if (c.Header.ToString().Equals("LINEA_TMP"))
            {
                c.Width = 75;
                e.Column.Header = "Tipo";
            }
            else
            {
                if (c.Header.ToString().Equals("TTT_TMP"))
                {
                    e.Column.Header = "Total";
                    c.Width = 120;
                    (e.Column as DataGridTextColumn).Binding.StringFormat = "{0:##,##.##}";
                    (e.Column as DataGridTextColumn).CellStyle = newCellStyleAlinearDerecha();
                }
                else
                {
                    c.Width = 40;
                    (e.Column as DataGridTextColumn).Binding.StringFormat = "{0:##,##.##}";
                    (e.Column as DataGridTextColumn).CellStyle = newCellStyleAlinearDerecha();
                }
            }
        }

        public static Style newCellStyleAlinearDerecha()
        {
            System.Windows.Style style = new Style(typeof(DataGridCell));
            style.Setters.Add(new System.Windows.Setter
            {
                Property = Control.HorizontalAlignmentProperty,
                Value = HorizontalAlignment.Right
            });
            return style;
        }
    }
}
